import {
    AutoComplete,
    InputNumber,
    Checkbox,
    Radio,
    Rate,
    Switch,
    DatePicker,
    TimePicker,
    Cascader,
    TreeSelect,
    Upload,
    Transfer,
    Pagination,
    Button,
    Slider
} from 'antd';
import { createElement } from 'react';
import { FormItemComponentProps } from 'react-antd-formutil';
import { picker, PickerPlugin } from './panel/Picker/config';

const injectFormProps: Omit<FormItemComponentProps, 'children'> = {
    name: undefined
};

const components = {
    AutoComplete,
    InputNumber,
    Checkbox,
    Radio,
    Rate,
    Switch,
    DatePicker,
    TimePicker,
    Cascader,
    TreeSelect,
    Upload,
    Transfer,
    Pagination,
    Button,
    Slider
};

const pluginsMap = Object.entries(components).reduce((acc, [name, component]) => {
    acc[name] = {
        component,
        options: {
            type: 'form-item',
            componentName: name,
            componentProps: {},
            formProps: {
                label: name,
                ...injectFormProps
            }
        }
    };

    return acc;
}, {} as Record<keyof typeof components, PickerPlugin>);

pluginsMap.Upload.options.componentProps.children = createElement(Button, { children: '上传' });

picker.use(...Object.values(pluginsMap));
